package com.gem.day04;

/**递归算法完成汉诺塔问题*/
public class Hanoit {
	public static void main(String[] args) {
		hanoit(3, 'A', 'B', 'C');
	}

	public static void move(char start, char end) {
		System.out.println(start + "->" + end);
	}

	public static void hanoit(int n, char one, char two, char three) {
		//递归出口,如果只有一个盘子
		if (n == 1) {
			move(one, three);
		} else {
			//把一塔上的盘子借住三塔移动到二塔上
			hanoit(n - 1, one, three, two);
			move(one, three);
			//把二塔上的盘子借住一塔移动到三塔上
			hanoit(n - 1, two, one, three);
		}
	}
}
